package com.lyhengtongwl.zqsnews.widget;

import android.app.Activity;
import android.os.CountDownTimer;
import android.widget.TextView;

import com.lyhengtongwl.zqsnews.App;
import com.lyhengtongwl.zqsnews.entity.NewsBaseEntity;
import com.lyhengtongwl.zqsnews.net.MyCallback;
import com.lyhengtongwl.zqsnews.net.Task;
import com.lyhengtongwl.zqsnews.utils.SPUtils;

import retrofit2.Response;

public class MyCountTimer extends CountDownTimer {

    /**
     * @Fields count : 倒计时
     */
    private static int count = 10 * 1000;
    private static int countDownInterval = 1000;

    private TextView mGetCode;
    private String id;
    private Activity activity;
    public MyCountTimer(Activity activity,TextView textView, String id) {
        super(count, countDownInterval);
        this.mGetCode = textView;
        this.id=id;
        this.activity=activity;
    }


    public MyCountTimer(long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);
    }

    /**
     * 倒计时过程中调用
     *
     * @param l
     */
    @Override
    public void onTick(long l) {
        mGetCode.setEnabled(false);
        mGetCode.setText(String.valueOf(l / 1000) + "s后重试");
    }

    /**
     * 倒计时完成后调用
     */
    @Override
    public void onFinish() {
//        getMoney();
    }
    //获取阅读收益
    private void getMoney() {
        String idStr = id;
        String readerIdStr = SPUtils.get(App.getContext(), "userId", "") + "";
        Task.getApiService().getMoney(idStr,readerIdStr).enqueue(new MyCallback<NewsBaseEntity>(activity) {
            @Override
            protected void onSuccess(Response<NewsBaseEntity> response) {

            }

            @Override
            protected void onFailure(Throwable t) {

            }
        });
    }
}
